package cn.dujy.derby.config;


import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * <p>
 *  MyBatisPlus 配置
 * </p>
 * @since 2023-12-06
 * @author 杜家源
 */
@MapperScan("cn.dujy.derby.mapper")
@Configuration
@EnableTransactionManagement
public class MyBatisPlusConfig {

    /**
     * 分页插件
     */
    @Bean
    public PaginationInterceptor paginationInnerInterceptor() {
        PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
        // 限制每页最大 1000
        paginationInterceptor.setLimit(1000);
        // 对于单一数据库类型来说,都建议配置DbType值,避免每次分页都去抓取数据库类型
        paginationInterceptor.setDbType(DbType.MYSQL);
        // 返回分页配置结果
        return paginationInterceptor;
    }

//    /**
//     * 乐观锁
//     */
//    @Bean
//    public MybatisPlusInterceptor mybatisPlusInterceptor() {
//        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
//        interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
//        return interceptor;
//    }

}
